<?php

/**
 * @author PeoneEr
 * @package aion personal cabinet v1.0
 * @copyright Aion Factory Inc. 2010-2011
 * @license GNU v3
 * @link Ai-Factory.ru && http://code.google.com/p/aionprivateofficev2
 */
require_once "core/application/models/msearch/msearch.php";
require_once "core/application/classes/errorClass.php";

class search_Controller extends Search_Model {

    private static $_instance = NULL;
	private $_params 	   = array();

    public static function getInstance() {
        if (is_null(self::$_instance)) {
            $class = __CLASS__;
            self::$_instance = new $class();
        }
        return self::$_instance;
    }

    private function catchParams() {
	/**
	 *  параметры в массив, точнее, строка поиска
	 *
	 */
        $params = array(
            'searchString' => $_POST['searchText']
        );
        return $params;
    }

    public function getSearch() {
	/**
	 *
	 *  поиск по персонажам
	 *
	 */
        $this->_params = $this->catchParams();
		try {
			foreach($this->_params as $key => $val) {
				if (empty($val) || !isset($val) || is_null($val)) {
					$this->echoError("Не указан ник");
				}
			}
		} catch (Exception $e) {
			echo $e->getMessage();
		}
        $this->_params['searchString'] = $this->secure($this->_params['searchString']);
        if (!$this->numRows($this->_params['searchString'])) {
            echo "<script language='javascript'> $.jmessage('Результаты поиска', 'По Вашему запросу никто не найден', 5000); </script>";
        } else {
            $this->redirect(0, "index?users&name=" . $this->_params['searchString']);
        }
        unset($this->_params);
    }

}

?>
